package com.example.concurrentprogramming8016.future.completablefuture;

import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.function.BiFunction;

/**
 * @author liyanhao
 * @Date 2023-01-08 20:57
 * 结果组合
 *
 */
public class ThenCombineDemo {
    public static void main(String[] args) {
        CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> {
            int number = new Random().nextInt(10);
            System.out.println("执行第一阶段 " + number);
            return number;
        });
        CompletableFuture<Integer> completableFuture1 = CompletableFuture.supplyAsync(() -> {
            int number = new Random().nextInt(10);
            System.out.println("第二阶段 " + number);
            return number;
        });
        CompletableFuture<Integer> completableFuture2 = completableFuture.thenCombine(completableFuture1, (integer, integer2) -> integer + integer2);
        System.out.println("最终计算的结果 " + completableFuture2.join());

    }
}
